﻿// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");

using System;
using System.Security.Principal;

namespace ConsoleApplication3delegate
{
    class DepositCard//储蓄卡
    {
        public int amount;

        public void Display()
        {
            Console.WriteLine("储蓄卡余额为：{0}", amount);
        }
        public void Account(int balance,int repayment)//还款
        {
            amount += balance;//amount余额
            Console.WriteLine("今天是本月的{0}，取款{1}，储蓄卡余额为：{2}。", DateTime.Today.Day, balance, amount);
        }
    }

    class CreditCard//信用卡
    {
        private int billamount;//账单金额
        private int repaymentday;//还款日

        public CreditCard(int billamount, int repaymentday)//创建信用卡
        {
            this.billamount = billamount;
            this.repaymentday = repaymentday;
        }

        public int getbillamount() { return billamount; }//信用卡查账单金额

        public int getrepaymentday() { return repaymentday; }//信用卡查还款日

        public void Display() { Console.WriteLine("信用卡余额为：{0}", billamount); }//信用卡查余额

    }

    class CreditCardDelegate//委托
    {
        public int billamount;//账单
        public int repaymentday;//还款日
        //请在此处添加自己的代码
        public delegate void DrdDelegate(int bill,int day);//委托声明
        public event DrdDelegate EvenDrd;
        public void Reply()
        {
            //Console.WriteLine("今天是{0}{1}",DateTime.Today.Day);
            if (DateTime.Today.Day == repaymentday)
            {
                EvenDrd(billamount, repaymentday);
                Console.WriteLine("还款成功");
            }
            else Console.WriteLine("未到达还款日，不扣款");
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            DepositCard depositCard = new DepositCard();//建立储蓄卡账户
            depositCard.amount = 10000;//初始余额10000
            CreditCard creditCard1 = new CreditCard(-2000, 6);//设置还款账单，还款日
            CreditCard creditCard2 = new CreditCard(-3000, 6);
            CreditCard creditCard3 = new CreditCard(-5000, 6);
            Console.WriteLine("");
            List<CreditCard> Cards = new List<CreditCard>();
            Cards.Add(creditCard1); Cards.Add(creditCard2); Cards.Add(creditCard3);//关联
            depositCard.Display();//储蓄卡余额
            Console.WriteLine("");
            CreditCardDelegate Six = new CreditCardDelegate();
            foreach (CreditCard card in Cards)
            {
                Console.WriteLine("信用卡开始执行委托还款。。。。。。");
                //请在此处添加自己的代码
                CreditCardDelegate delegate1= new CreditCardDelegate();
                delegate1.billamount=card.getbillamount();
                delegate1.repaymentday=card.getrepaymentday();
                delegate1.EvenDrd += new CreditCardDelegate.DrdDelegate(depositCard.Account);
                delegate1.Reply();
               
               // creditCard1.Display();
                Console.WriteLine("");
            }
            Console.ReadLine();
        }
    }
}